﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyGUI.wcfFlightService;
using MyGUI.Properties;
using Model_Layer;

namespace MyGUI
{
    public partial class AllFlights : Form
    {
        private wcfFlightService.IService wcfservice;
        public AllFlights()
        {
            wcfservice = new wcfFlightService.ServiceClient();
            InitializeComponent();
        }

        private void Child1_Load(object sender, EventArgs e)
        {
            try
            {
                List<Flight> flightArray = wcfservice.GetAllFlights(true);
                
                //List<object> myNewList = new List<object>(flightArray);
                //if (myNewList != null)
                if (flightArray != null)
                {
                    //foreach (Flight flight in myNewList)                
                    foreach (Flight flight in flightArray)
                    {
                        ListViewItem listViewItem = new ListViewItem(flight.Idflight.ToString());
                        listViewItem.SubItems.Add(flight.Objairplane.Idairplane.ToString());
                        listViewItem.SubItems.Add(flight.Traveltime.ToString());
                        listViewItem.SubItems.Add(flight.Timeofdeparture);
                        listViewItem.SubItems.Add(flight.Timeofarrival);
                        listViewItem.SubItems.Add(flight.Availableseats.ToString());
                        listViewItem.SubItems.Add(flight.Takenseats.ToString());
                        listViewItem.SubItems.Add(flight.Price.ToString());
                        listViewItem.SubItems.Add(flight.StartAirport.Name.ToString());
                        listViewItem.SubItems.Add(flight.DestinationAirport.Name.ToString());
                        listViewObj.Items.Add(listViewItem);


                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Child1_Shown(object sender, EventArgs e)
        {

        }

        private void listViewObj_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}


